﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Acme.ShopStore.Logins
{
    public class LoginShopAppService : ApplicationService, IShopLoginAppService
    {
        private IRepository<ShopLogin, Guid> _repository;
        public LoginShopAppService(IRepository<ShopLogin, Guid> repository)
        {
            _repository = repository;
        }

        //注册
        [HttpPost]
        public async Task<LoginShopDto> UserAdd(CreateUpdateLoginShopDto dto)
        {
            //dto.UserPass = Md5.GetMd5(dto.UserPass);
            var Login = await _repository.InsertAsync(ObjectMapper.Map<CreateUpdateLoginShopDto, ShopLogin>(dto));
            return ObjectMapper.Map<ShopLogin, LoginShopDto>(Login);
        }

        [HttpPost]
        //登录
        public int UserLogin(string UserCrod, string UserPass)
        {
            //UserPass = Md5.GetMd5(UserPass);
            var Login = _repository.Where(s => s.UserCrod.Equals(UserCrod) && s.UserPass.Equals(UserPass)).Count();
            return Login;
        }
    }
}
